<?php

/**
 * Usuario form.
 *
 * @package    auip
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */

class UserForm extends sfForm
{
  public function configure()
  {
	
      
       $this->setWidgets(array(
      'email'     => new sfWidgetFormInputText(array('label' => 'Email'),array('style' => 'width: 280px;')),//'size' => '35')),
      'nombre'    => new sfWidgetFormInputText(array('label' => 'Nombre'),array('style' => 'width: 280px;')),
      'apellidos' => new sfWidgetFormInputText(array('label' => 'Apellidos'),array('style' => 'width: 280px;')),
      'password'  => new sfWidgetFormInputPassword(array('label' => 'Contraseña'),array('style' => 'width: 280px;')),
      'password2'  => new sfWidgetFormInputPassword(array('label' => 'Confirmar Contraseña'), array('maxlength'=>'10', 'style' => 'width: 280px;')),
    ));

    $this->setValidators(array(
      'email'     => new sfValidatorEmail(array('required'=>true), array('required'=> "El email es obligatorio")),
      'nombre'    => new sfValidatorString(),
      'apellidos' => new sfValidatorString(),
      'password'  => new sfValidatorString(),
      'password2'  => new sfValidatorString(),
    ));

    $this->widgetSchema->setNameFormat('usuario[%s]');
/*
    $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
            new sfValidatorSchemaCompare('password2', sfValidatorSchemaCompare::EQUAL, 'password', array('throw_global_error' => true), array('invalid' => "Las dos contraseñas no coinciden")),
            new sfValidatorDoctrineUnique(array('model' => 'Usuario', 'column' => 'email', 'primary_key' => 'id', 'required' => true), array('invalid'=> "Este email ya está en uso"))
        )));

    $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
*/
    $decorator = new myWidgetFormSchemaFormatterCustom($this->getWidgetSchema());
  	$this->widgetSchema->addFormFormatter('custom', $decorator);
  	$this->widgetSchema->setFormFormatterName('custom');
    
    parent::setup();
    

      $this->validatorSchema->setPostValidator(new sfValidatorAnd(array(
            new sfValidatorSchemaCompare('password2', sfValidatorSchemaCompare::EQUAL, 'password', array('throw_global_error' => true), array('invalid' => "Las dos contraseñas no coinciden")),
            new sfValidatorDoctrineUnique(array('model' => 'Usuario', 'column' => 'email', 'primary_key' => 'id', 'required' => true), array('invalid'=> "Este email ya está en uso"))
        )));

      $this->errorSchema = new sfValidatorErrorSchema($this->validatorSchema);
        
     //   $this->widgetSchema->setNameFormat('megaUsuario[%s]'); 
  }
}